package com.yuesystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuesystem.common.CustomException;
import com.yuesystem.entity.FixedItem2;
import com.yuesystem.entity.OfficeItem;
import com.yuesystem.mapper.OfficeItemMapper;
import com.yuesystem.service.FixedItem2Service;
import com.yuesystem.service.OfficeItemService;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



/**
 * 官职条目接口实现类.
 */
@Service
@Slf4j
public class OfficeItemServiceImpl extends ServiceImpl<OfficeItemMapper, OfficeItem>
    implements OfficeItemService {
  @Autowired
  private FixedItem2Service fixedItem2Service;
  
  /**
   * 根据官职id获得该官职可变条目信息.
   *
   * @param id 官职id
   * @return 条目信息
   */
  @Override
  public List<OfficeItem> getItems(Long id) {
    // 展示未删除的修改信息
    LambdaQueryWrapper<OfficeItem> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(OfficeItem::getOfficeId, id)
        .eq(OfficeItem::getIsDeleted, 0)
        .ne(OfficeItem::getRelation, "朝代")
        .ne(OfficeItem::getRelation, "品阶")
        .ne(OfficeItem::getRelation, "类型");
    
    List<OfficeItem> list = this.list(queryWrapper);
    return list;
  }
  
  /**
   * 根据官职id获得固定条目信息.
   *
   * @param id 官职id
   * @return 条目信息
   */
  @Override
  public List<FixedItem2> getFixed(Long id) {
    LambdaQueryWrapper<FixedItem2> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(FixedItem2::getOfficeId, id);
    List<FixedItem2> list = fixedItem2Service.list(queryWrapper);
    return list;
  }
  
  
  /**
   * 根据id获得官职条目信息.
   *
   * @param id 条目id
   * @return 条目
   */
  @Override
  public OfficeItem getItemById(Long id) {
    
    LambdaQueryWrapper<OfficeItem> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(OfficeItem::getIsDeleted, 0);
    queryWrapper.eq(OfficeItem::getId, id);
    OfficeItem item = this.getOne(queryWrapper);
    if (item == null) {
      throw new CustomException("该条目不存在，请刷新后重试！");
    }
    return item;
  }
  
  
}

